package com.taotao.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.apitype.ApiHepler;
import com.taotao.apitype.ApiHepler.PagingResult;
import com.taotao.dao.TbOrderItemMapper;
import com.taotao.dao.TbOrderMapper;
import com.taotao.dao.TbOrderShippingMapper;
import com.taotao.domain.TbItem;
import com.taotao.domain.TbOrder;
import com.taotao.domain.TbOrderExample;
import com.taotao.domain.TbOrderExample.Criteria;
import com.taotao.domain.TbOrderItem;
import com.taotao.domain.TbOrderShipping;
import com.taotao.viewmodel.OrderRequest;

@Service
public class OrderImpl {
	@Autowired
	TbOrderMapper orderMapper;
	@Autowired
	TbOrderItemMapper orderItemMapper;
	@Autowired
	TbOrderShippingMapper orderShippingMapper;

	/**
	 * 查询订单列表分页
	 * 
	 * @param page
	 * @param rows
	 * @param username
	 * @return
	 * @throws Exception
	 */
	public ApiHepler.PagingResponse<TbOrder> orderList(Map<String, Object> data) throws Exception {
		PagingResult pagingResult = new ApiHepler.PagingResult();
		// 自动赋值分页请求对象
		BeanUtils.populate(pagingResult, data);
		System.out.println("PagingResult cast:" + pagingResult.toString());
		// 分页处理
		PageHelper.startPage(pagingResult.getPage(), pagingResult.getSize());
		// 执行查询
		TbOrderExample example = new TbOrderExample();
		List<TbOrder> list = orderMapper.selectByExample(example);
		// 取分页信息
		PageInfo<TbOrder> pageInfo = new PageInfo<TbOrder>(list);
		// 返回分页结果
		return ApiHepler.Paging(pageInfo.getList(), pageInfo.getTotal());
	}

	public ApiHepler.MessageResult orderSave(OrderRequest data) throws Exception {

		return ApiHepler.MessBox("添加成功！", true, null);
	}
}
